package Main;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class WebsiteReader {

	public String websiteToString(String urlString) {
		String pageString = "";
		BufferedReader reader;
		try {
			URL url = new URL(urlString);
			HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			huc.setRequestMethod("HEAD");
			if (huc.getResponseCode() != HttpURLConnection.HTTP_OK)
			{
				System.out.println(urlString + " does not exist!");
				return "";
			}

			reader = new BufferedReader(new InputStreamReader(url.openStream()));
			String line = reader.readLine();

			while (line != null) {
				pageString += line + '\n';
				line = reader.readLine();
			}
		} catch (Exception e) {
			System.out.println("ERROR: url bad: "+  urlString);
		}
		return pageString;
	}
}
